﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace NEMproject
{
    public partial class ParametersWindow : Form
    {

        public ParametersWindow()
        {
            InitializeComponent();
        }

        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            base.OnFormClosing(e);

            if (e.CloseReason == CloseReason.WindowsShutDown) return;

            this.Hide();
        }

        private void parameterWindow_OK_Click(object sender, EventArgs e)
        {
            saveParameterWindowSettings();
            Properties.Settings.Default.Save();
            this.Hide();
        }

        private void parameterWindow_Cancel_Click(object sender, EventArgs e)
        {
            loadParameterWindowSettings();
            this.Hide();
        }

        public void loadParameterWindowSettings()
        {
         
            this.BasicFuelPrice.Text = Properties.Settings.Default.BaseFuelPrice.ToString();
            this.VatRate.Text = Properties.Settings.Default.VAT_rate.ToString();
            this.VarPr1.Text = Properties.Settings.Default.VarPr1.ToString();
            this.VarPr2.Text = Properties.Settings.Default.VarPr2.ToString();
            this.VarPr3.Text = Properties.Settings.Default.VarPr3.ToString();
            this.VarPr4.Text = Properties.Settings.Default.VarPr4.ToString();
            this.VarPr5.Text = Properties.Settings.Default.VarPr5.ToString();
            this.FixedPriceScale1.Text = Properties.Settings.Default.FixedPriceScale1.ToString();
            this.FixedPriceScale2.Text = Properties.Settings.Default.FixedPriceScale2.ToString();
            this.FixedPriceScale3.Text = Properties.Settings.Default.FixedPriceScale3.ToString();
            this.FixedPriceScale4.Text = Properties.Settings.Default.FixedPriceScale4.ToString();
            this.FixedPriceScale5.Text = Properties.Settings.Default.FixedPriceScale5.ToString();
            this.EnergyConsumptionThreshold1.Text = Properties.Settings.Default.Threshold1.ToString();
            this.EnergyConsumptionThreshold2.Text = Properties.Settings.Default.Threshold2.ToString();
            this.EnergyConsumptionThreshold3.Text = Properties.Settings.Default.Threshold3.ToString();
            this.EnergyConsumptionThreshold4.Text = Properties.Settings.Default.Threshold4.ToString();
            this.YearHorizon.Text = Properties.Settings.Default.YearHorizon.ToString();
        }

        private void saveParameterWindowSettings()
        {
            Properties.Settings.Default.BaseFuelPrice = int.Parse(this.BasicFuelPrice.Text);
            Properties.Settings.Default.VAT_rate = double.Parse(this.VatRate.Text);
            Properties.Settings.Default.VarPr1 = double.Parse(this.VarPr1.Text);
            Properties.Settings.Default.VarPr2 = double.Parse(this.VarPr2.Text);
            Properties.Settings.Default.VarPr3 = double.Parse(this.VarPr3.Text);
            Properties.Settings.Default.VarPr4 = double.Parse(this.VarPr4.Text);
            Properties.Settings.Default.VarPr5 = double.Parse(this.VarPr5.Text);
            Properties.Settings.Default.FixedPriceScale1 = double.Parse(this.FixedPriceScale1.Text);
            Properties.Settings.Default.FixedPriceScale2 = double.Parse(this.FixedPriceScale2.Text);
            Properties.Settings.Default.FixedPriceScale3 = double.Parse(this.FixedPriceScale3.Text);
            Properties.Settings.Default.FixedPriceScale4 = double.Parse(this.FixedPriceScale4.Text);
            Properties.Settings.Default.FixedPriceScale5 = double.Parse(this.FixedPriceScale5.Text);
            Properties.Settings.Default.Threshold1 = int.Parse(this.EnergyConsumptionThreshold1.Text);
            Properties.Settings.Default.Threshold2 = int.Parse(this.EnergyConsumptionThreshold2.Text);
            Properties.Settings.Default.Threshold3 = int.Parse(this.EnergyConsumptionThreshold3.Text);
            Properties.Settings.Default.Threshold4 = int.Parse(this.EnergyConsumptionThreshold4.Text);
            Properties.Settings.Default.YearHorizon = int.Parse(this.YearHorizon.Text);
        }


    }
}
